package org.datascooter.meta;

import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Purposed for store dynamic info about database types for manage sql queries building. Can be stored to xml for futher building of org.datascooter.map.DataType - storage for static data types info
 * 
 * @author nemo
 * 
 */
public class DataTypeInfo implements Serializable {

	private static final long serialVersionUID = 6973196593374057341L;
	public final String name;
	public final int sqlType;
	public final int precision;
	public final String literalPrefix;
	public final String literalSuffix;
	public final String createParams;
	public final boolean nullable;
	public final boolean caseSensitive;
	public final int searcheable;
	public final boolean unsigned;
	public final int maxScale;
	public final int minScale;

	@SuppressWarnings("nls")
	public DataTypeInfo(ResultSet typeResultSet) throws SQLException {
		name = typeResultSet.getString("TYPE_NAME");
		sqlType = typeResultSet.getInt("DATA_TYPE");
		precision = typeResultSet.getInt("PRECISION");
		literalPrefix = typeResultSet.getString("LITERAL_PREFIX");
		literalSuffix = typeResultSet.getString("LITERAL_SUFFIX");
		createParams = typeResultSet.getString("CREATE_PARAMS");
		nullable = typeResultSet.getInt("NULLABLE") == 0 ? false : true;
		caseSensitive = typeResultSet.getBoolean("CASE_SENSITIVE");
		searcheable = typeResultSet.getInt("SEARCHABLE");
		unsigned = typeResultSet.getBoolean("UNSIGNED_ATTRIBUTE");
		maxScale = typeResultSet.getInt("MAXIMUM_SCALE");
		minScale = typeResultSet.getInt("MINIMUM_SCALE");
	}
	// @SuppressWarnings("nls")
	// public String toXML() {
	// StringBuilder builder = new StringBuilder();
	// builder.append("\n<dataType");
	// builder.append(" name=\"" + name + "\" ");
	// builder.append(" precision=\"" + precision + "\" ");
	// builder.append(" createParams=\"" + createParams + "\" ");
	// builder.append(" nullable=\"" + nullable + "\" ");
	// builder.append(" caseSensitive=\"" + caseSensitive + "\" ");
	// builder.append(" unsigned=\"" + unsigned + "\" ");
	// builder.append(" maxScale=\"" + maxScale + "\" ");
	// builder.append(" minScale=\"" + minScale + "\" ");
	// builder.append("/>");
	// return builder.toString();
	// }
}
